<include file="public@header" />
<style>
    .active {
        background: #1890ff;
    }
    .active a{
        color: #fff;
    }
</style>
</head>
<body>
    <div class="layui-fluid js-check-wrap">
        <div class="layui-card">
            <div class="layui-card-header">{:lang('ADMIN_RBAC_AUTHORIZE')}</div>
            <div class="layui-card-body">
                <form class="js-ajax-form clearfix layui-col-space10"  action="{:url('rbac/authorizePost')}" method="post">
                    <if condition="count($sites) gt 1">
                        <div class="layui-col-md2 layui-col-sm3 layui-col-lg2">
                            <table class="layui-table">
                                <thead>
                                    <tr><th><p class="list-group-item" style="font-weight:bold;"><i class="fa fa-sitemap normal"></i> 站点选择</p></th></tr>
                                </thead>
                                <volist name="sites" id="vo">
                                    <tr>
                                        <td class="<if condition="$vo['site_id'] == $site_id">active</if>"><a style="font-size:13px;display:block;" class="list-group-item  " href="{:url('Rbac/authorize',array('id'=>$roleId, 'site_id'=>$vo['site_id']))}">{$vo.name}</a></td>
                                    </tr>
                                </volist>
                            </table>
                        </div>
                    </if>

                    <div class="layui-col-md10 layui-col-sm9 layui-col-lg10">
                        <table class="layui-table" id="authrule-tree">
                            <thead>
                                <tr><th>常规操作权限</th></tr>
                            </thead>
                            <tbody>
                                <if condition="$category">
                                    {$category}
                                </if>
                            </tbody>
                        </table>
                        
                        <div class="well">
                            <input type="hidden" name="roleId" value="{$roleId}" />
                            <input type="hidden" name="site_id" value="{$site_id}" />
                            <button class="layui-btn layui-btn-normal js-ajax-submit" type="submit">{:lang('SAVE')}</button>
                            <a class="layui-btn layui-btn-primary" href="{:url('admin/rbac/index')}">{:lang('BACK')}</a>
                        </div>
                    </div>
                        
                </form>
            </div>
        </div>
    </div>
    <script src="__STATIC__/js/admin.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
        Wind.css('treeTable');
        Wind.use('treeTable', function () {
            $("#authrule-tree").treeTable({
                indent: 20
            });
        });
    });

    function checknode(obj) {
        var chk = $("input[type='checkbox']");
        var count = chk.length;

        var num = chk.index(obj);
        var level_top = level_bottom = chk.eq(num).attr('level');
        for (var i = num; i >= 0; i--) {
            var le = chk.eq(i).attr('level');
            if (le <level_top) {
                chk.eq(i).prop("checked", true);
                var level_top = level_top - 1;
            }
        }
        for (var j = num + 1; j < count; j++) {
            var le = chk.eq(j).attr('level');
            if (chk.eq(num).prop("checked")) {

                if (le > level_bottom){
                    chk.eq(j).prop("checked", true);
                }
                else if (le == level_bottom){
                    break;
                }
            } else {
                if (le >level_bottom){
                    chk.eq(j).prop("checked", false);
                }else if(le == level_bottom){
                    break;
                }
            }
        }
    }
    </script>
</body>
</html>
